home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 13525 < prev    next >
Encoding:
Text File  |  1996-08-05  |  2.6 KB  |  62 lines

  1. Newsgroups: comp.lang.c++
  2. Path: netcom.com!marnold
  3. From: marnold@netcom.com (Matt Arnold)
  4. Subject: Re: What is : void class::method(TYPE* type) throw()
  5. Message-ID: <marnoldDov7G4.H3M@netcom.com>
  6. Organization: NETCOM On-line Communication Services (408 261-4700 guest)
  7. References: <4j5jfc$hk3@doc.zippo.com>
  8. Date: Tue, 26 Mar 1996 07:57:40 GMT
  9. Sender: marnold@netcom16.netcom.com
  10.  
  11. Gilad Brand writes:
  12.  
  13. >I read an article in the "C++ Report" which carried the name: "C++ Exception -
  14. >Handling in Multithreaded Programs" / by Sean Leary. 
  15. >In the article I saw some examples of code which syntax was unfamiliar to me.
  16. >The formal declaration of a method was written like this:
  17.  
  18. >void EHThread::terminate(EHThread* self) throw()
  19. >{
  20. >    ...
  21. >}
  22.  
  23. >This syntax returned in other places in the article.
  24. >I wonder if there is anyone who is familiar with this syntax, and can tell
  25. >me what is its meaning ?
  26. >Thanks,
  27.  
  28. I assume you recognize the syntax for a member function definition and
  29. that it is the "throw()" that is, er, throwing you.
  30.  
  31. That syntax is an "exception specification".  An exception specification
  32. lists the exception types a function is allowed to throw.  If any
  33. exception not in the list *is* thrown from within the function (or some
  34. code called by the function), unexpected() will be called.  The default 
  35. behavior of unexpected() is to terminate the program.
  36.  
  37. The above syntax of an empty list is the special case indicating that
  38. EHThread::terminate() should throw any exceptions.  Someone is trying to
  39. make it clear that this member is not allowed (or does not) to raise any 
  40. kind of exception.
  41.  
  42. On the other hand, if the member *was* allowed to throw, say, Foo and 
  43. Bar exceptions, for example, the code would have looked like this...
  44.  
  45. void EHThread::terminate(EHThread* self) throw(Foo, Bar)
  46.  
  47. Some folks in the C++ community doubt the usefullness of exception
  48. specifications.  They are somewhat tedious to use and, perhaps, a little
  49. bit too error-prone (using them causually may cause code to terminate
  50. when you didn't really want it to).  I urge you to read more about them 
  51. in any C++ books you can find that cover them and come to your own 
  52. decisions.
  53.  
  54. Regards,
  55. -------------------------------------------------------------------------
  56. Matt Arnold                       |        | ||| | |||| |  | | || ||
  57. marnold@netcom.com                |        | ||| | |||| |  | | || ||
  58. Boston, MA                        |      0 | ||| | |||| |  | | || ||
  59. 617.389.7384 (h) 617.576.2760 (w) |        | ||| | |||| |  | | || ||
  60. C++, MIDI, Win32/95 developer     |        | ||| 4 3 1   0 8 3 || ||
  61. -------------------------------------------------------------------------
  62.